import sensor
import image
import lcd
import time
lcd.init()
sensor.reset()
sensor.set_pixformat(sensor.RGB565)
sensor.set_framesize(sensor.VGA)
sensor.set_auto_gain(False) # must be turned off for color tracking
sensor.set_auto_whitebal(False) # must be turned off for color tracking
sensor.run(1)
green_threshold   = (0, 100, -128, -30, -128, 127)
red_threshold   = (0, 100, 35, 127, -128, 127)

clk = time.clock()
while True:
   # clk.tick()
    img=sensor.snapshot()
	blobs = img.find_blobs([green_threshold], pixels_threshold=20, area_threshold=20,merge = True)
	if blobs:
	    for b in blobs:
		    tmp=img.draw_rectangle(b[0:4])
			tmp=img.draw_cross(b[5], b[6])
			blobs = img.find_blobs([red_threshold], pixels_threshold=10 , area_threshold=10)
			if blobs:
			for b in blobs:
			tmp=img.draw_cross(b[5], b[6])
			print(b[5],b[6])
			#print(clk.fps())



